//
//  YYNameSilderView.m
//  CollarMicrophone
//
//  Created by Yown on 2024/4/10.
//

#import "YYNameSilderView.h"

#import <BIToolModule/BIProjectDefine.h>
#import <BIProjectModule/BIAppDefine.h>

@interface YYNameSilderView ()

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UISlider *sliderView;
@property (weak, nonatomic) IBOutlet UILabel *currentValueLabel;

@end

@implementation YYNameSilderView

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupViews];
}

- (void)setupViews {
    self.backgroundColor = [UIColor clearColor];
    self.nameLabel.textColor = [UIColor loadColorFromString:@"#333333"];
    self.nameLabel.font = BIFont(14);
    
    self.sliderView.value = 0;
    self.sliderView.maximumValue = 10;
    self.sliderView.maximumTrackTintColor = [UIColor loadColorFromString:@"F4F4F4"];
    self.sliderView.minimumTrackTintColor = [UIColor loadColorFromString:@"#4CB49E"];
    [self.sliderView setThumbImage:[UIImage imageNamed:@"home_slider_thumb"] forState:UIControlStateNormal];
    
    self.currentValueLabel.textColor = [UIColor loadColorFromString:@"#828282"];
    self.currentValueLabel.font = BIFont(12);
    self.currentValueLabel.text = @"0";
}

- (void)setupMinValue:(NSUInteger)minValue maxValue:(NSUInteger)maxValue {
    self.sliderView.minimumValue = minValue;
    self.sliderView.maximumValue = maxValue;
}

- (void)reloadName:(NSString *)name {
    self.nameLabel.text = name;
}

- (void)reloadProgress:(NSUInteger)progress {
    self.sliderView.value = progress;
    self.currentValueLabel.text = [NSString stringWithFormat:@"%ld", progress];
}

#pragma mark - Action

- (IBAction)moveSlider:(UISlider *)slider {
    CGFloat value = round(slider.value);
    self.sliderView.value = value;
    self.currentValueLabel.text = [NSString stringWithFormat:@"%ld", [@(value) unsignedIntegerValue]];
    BISafeBlock(self.sliderValueChangedBlock, @(value));
}

@end
